/**
 * Created by cjd on 2016/5/4.
 */
angular.module("app").factory("timestampMarker", ["$rootScope", "$timeout", function ($rootScope, $timeout) {
    return {
        request: function (config) {
            var headersGetter = config.headers;
            if ((headersGetter["Accept"] && headersGetter["Accept"].split(",")[0]) == "application/json" && config["url"].indexOf("template") < 0) {
                $rootScope.loading = true;
                config.requestTimestamp = new Date().getTime();
                config.url = $rootScope.sysOrigin + config.url;
            }
            return config;
        },
        response: function (response) {
            response.config.responseTimestamp = new Date().getTime();
            return response;
        }
    };
}]);
angular.module("app")
    .factory("User", ["$resource", function ($resource) {
        return $resource("", {}, {
            Login: {
                cache: false,
                method: "POST",
                url: "/user/login",
                isArray: false
            },
            changePassword: {
                cache: false,
                method: "POST",
                url: "/user/changePassword",
                isArray: false
            },
            resetPassword: {
                cache: false,
                method: "POST",
                url: "/user/resetPassword",
                isArray: false
            },
            sendSMS: {
                cache: false,
                method: "POST",
                url: "/user/sendCode",
                isArray: false
            },
            // checkPassword: {
            //     cache: false,
            //     method: "POST",
            //     url: "/user/checkPassword",
            //     isArray: false
            // },
            getList: {
                cache: false,
                method: "POST",
                url: "/user/list",
                isArray: false
            },
            userEdit: {
                cache: false,
                method: "POST",
                url: "/user/edit",
                isArray: false
            },
            getUserInfo: {
                cache: false,
                method: "POST",
                url: "/user/info",
                isArray: false
            },
            getConfig: {
                cache: false,
                method: "GET",
                url: "/index/getConfig",
                isArray: false
            }
        });
    }])
    .factory("topic", ["$resource", function ($resource) {
        return $resource("", {}, {
            getList: {
                cache: false,
                method: "POST",
                url: "/topic/list",
                isArray: false
            },
            getInfo: {
                cache: false,
                method: "POST",
                url: "/topic/info",
                isArray: false
            },
            saveInfo: {
                cache: false,
                method: "POST",
                url: "/topic/save",
                isArray: false
            },
            getComments: {
                cache: false,
                method: "POST",
                url: "/topic/comment",
                isArray: false
            },
            invalid: {
                cache: false,
                method: "POST",
                url: "/topic/invalid",
                isArray: false
            },
            effective: {
                cache: false,
                method: "POST",
                url: "/topic/effective",
                isArray: false
            },
            updateTop: {
                cache: false,
                method: "POST",
                url: "/topic/updateTop",
                isArray: false
            }
        });
    }])
    .factory("welfare", ["$resource", function ($resource) {
        return $resource("", {}, {
            getWelfareList: {
                cache: false,
                method: "POST",
                url: "/welfare/pageList",
                isArray: false
            },
            saveWelfare: {
                cache: false,
                method: "POST",
                url: "/welfare/save",
                isArray: false
            },
            pushWelfare: {
                cache: false,
                method: "POST",
                url: "/welfare/push",
                isArray: false
            },
            deleteWelfare: {
                cache: false,
                method: "POST",
                url: "/welfare/delete",
                isArray: false
            },
            getWelfareItemList: {
                cache: false,
                method: "POST",
                url: "/welfareItem/list",
                isArray: false
            },
            uploadWelfareItem: {
                cache: false,
                method: "POST",
                url: "/welfareItem/upload",
                isArray: false
            }
        });
    }])
    // .factory("activitySign", ["$resource", function ($resource) {
    //     return $resource("", {}, {
    //         listByUser: {
    //             cache: false,
    //             method: "POST",
    //             url: "/activitySign/listByUser",
    //             isArray: false
    //         }
    //     });
    // }])
    // .factory("groupVerify", ["$resource", function ($resource) {
    //     return $resource("", {}, {
    //         getList: {
    //             cache: false,
    //             method: "POST",
    //             url: "/orgVerify/list",
    //             isArray: false
    //         },
    //         checkFail: {
    //             cache: false,
    //             method: "POST",
    //             url: "/orgVerify/checkFail",
    //             isArray: false
    //         },
    //         checkSuccess: {
    //             cache: false,
    //             method: "POST",
    //             url: "/orgVerify/checkSuccess",
    //             isArray: false
    //         }
    //     });
    // }])
;